package com.ruoyi.web.controller.inventory;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.SeqNumberUtils;
import com.ruoyi.inventory.domain.TInventoryAllot;
import com.ruoyi.inventory.service.ITInventoryAllotService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调拨Controller
 * 
 * @author cy
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/allot/allot")
public class TInventoryAllotController extends BaseController
{
    @Autowired
    private ITInventoryAllotService tInventoryAllotService;

    /**
     * 查询调拨列表
     */
    @PreAuthorize("@ss.hasPermi('allot:allot:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInventoryAllot tInventoryAllot)
    {
        startPage();
        List<TInventoryAllot> list = tInventoryAllotService.selectTInventoryAllotList(tInventoryAllot);
        return getDataTable(list);
    }

    /**
     * 导出调拨列表
     */
    @PreAuthorize("@ss.hasPermi('allot:allot:export')")
    @Log(title = "调拨", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInventoryAllot tInventoryAllot)
    {
        List<TInventoryAllot> list = tInventoryAllotService.selectTInventoryAllotList(tInventoryAllot);
        ExcelUtil<TInventoryAllot> util = new ExcelUtil<TInventoryAllot>(TInventoryAllot.class);
        util.exportExcel(response, list, "调拨数据");
    }

    /**
     * 获取调拨详细信息
     */
    @PreAuthorize("@ss.hasPermi('allot:allot:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tInventoryAllotService.selectTInventoryAllotById(id));
    }

    /**
     * 新增调拨
     */
    @PreAuthorize("@ss.hasPermi('allot:allot:add')")
    @Log(title = "调拨", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInventoryAllot tInventoryAllot)
    {
        tInventoryAllot.setDocument(SeqNumberUtils.getDBBDNum());
        return toAjax(tInventoryAllotService.insertTInventoryAllot(tInventoryAllot));
    }

    /**
     * 修改调拨
     */
    @PreAuthorize("@ss.hasPermi('allot:allot:edit')")
    @Log(title = "调拨", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInventoryAllot tInventoryAllot)
    {
        return toAjax(tInventoryAllotService.updateTInventoryAllot(tInventoryAllot));
    }

    /**
     * 删除调拨
     */
    @PreAuthorize("@ss.hasPermi('allot:allot:remove')")
    @Log(title = "调拨", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long ids)
    {
        return toAjax(tInventoryAllotService.deleteTInventoryAllotById(ids));
    }

    /**
     * 撤销审批
     */
    @PutMapping ("updateStatus")
    public R selectAll(String document){
        return R.ok(this.tInventoryAllotService.upInventoryAllot(0, 0, document));
    }

    /**
     * 提交审批
     */
    @PutMapping ("update")
    public R upState(String document){
        return R.ok(this.tInventoryAllotService.upInventoryAllot(1, 1, document));
    }
}
